// pages/applyList/applyList.js


const mdCode = require('../../utils/md5.js');
const desCode = require('../../utils/aesUtil.js');
const api_js = require("../../utils/api.js");
const timeUtils = require("../../utils/time.js");
var app = getApp();


Page({

  /**
   * 页面的初始数据
   */
  data: {
    bar_Height: wx.getSystemInfoSync().statusBarHeight,

    isIphoneX_: getApp().globalData.isIphoneX,


    displayI:'',
    displayN:'',
    ToLoad: '',
    
    albumList: [],
    isDelegateArray: [],
    page: 0,
    allPage: ''


  },

  checkFun(e) {
    console.log(e.currentTarget.dataset.id);

    let customerid = e.currentTarget.dataset.id;

    // ==========================(109)报名详情================================================
    // 入参：
    //   customerid ///活动报名id

    var wMsgID = desCode.wMsgID();
    var wParam = desCode.to3des(`customerid=${customerid}`);
    var md = mdCode.hexMD5('9999' + '109' + wMsgID + wParam + 'q1w2e3r4t5y6');
    const data = {
      wAgent: 9999,
      wAction: 109,
      wMsgID: wMsgID,
      wParam: wParam,
      wSign: md,
      wImei: 222,
      wVersion: 2,
      wRequestUserID: 4
    }
    api_js.postReq(data, (res) => {
      console.log(res, "报名详情");


      let barcode = res.Data[0].barcodes[0].barcode;
      let barcodeimg = res.Data[0].barcodes[0].barcodeimg;
      let barstatus = res.Data[0].barcodes[0].barstatus;
      let name = res.Data[0].name;
      let meetingplace = res.Data[0].meetingplace;
      let participantstime = res.Data[0].participantstime.split(' ')[0];
      let logo = res.Data[0].logo;
      let description = res.Data[0].description;
      let remark = res.Data[0].remark;

      console.log(barcode, "barcode");
      console.log(barcodeimg, "barcodeimg");
      // (0:未使用 1：已失效 2：已使用 3:已删除)
      console.log(barstatus, "barstatus");
      console.log(name, "name");
      console.log(meetingplace, "meetingplace");
      console.log(participantstime, "participantstime");

      // return;


      wx.navigateTo({
        url: `../QRCode/QRCode?barcode=${barcode}&barcodeimg=${barcodeimg}&barstatus=${barstatus}&name=${name}&meetingplace=${meetingplace}&participantstime=${participantstime}&logo=${logo}&description=${description}&remark=${remark}`
      })

      
    })

  },



  // 商家相册列表
  getAlbum(page, size) {
    var that = this;
    let wMsgID = desCode.wMsgID();
    let wParam = desCode.to3des(`userid=${app.globalData.UserID}_page=${page}_size=${size}`);
    let md = mdCode.hexMD5('9999' + '108' + wMsgID + wParam + 'q1w2e3r4t5y6');
    const data = {
      wAgent: 9999,
      wAction: 108,
      wMsgID: wMsgID,
      wParam: wParam,
      wSign: md,
      wImei: 222,
      wVersion: 2,
      wRequestUserID: 4
    }
    api_js.postReq(data, (res) => {
      console.log(res);
      if (res.ReturnCode == 0) {
        if (res.Data != '') {
          that.setData({
            displayI: 'none',
            displayN: '',
          })
        } else {
          that.setData({
            displayI: '',
            displayN: 'none'
          })
        }
        var loadLength = res.Data.length
        if (loadLength <= 9) {
          that.setData({
            ToLoad: '',
          });
        } else {
          that.setData({
            ToLoad: 'none',
          });
        }
        this.setData({
          allPage: res.PageCount
        })
        if (loadLength > 0) {
          let isDelegateArr = []
          this.setData({
            albumList: this.data.albumList.concat(res.Data),
            isDelegateArray: isDelegateArr
          });

          // item.isexpired 是否过期 0是过期 1未过期
        }
      } else if (res.ReturnCode == 110){
        console.log("空数据");
        that.setData({
          ToLoad: 'none',
        });
      }
    })
  },




  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.setData({
      albumList: [],
      allAlbum: []
    })
    this.getAlbum(0, 10)


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  /**
   * 页面上拉触底事件的处理函数
   */

  onReachBottom() {
    var that = this;
    console.log(this.data.page, that.data.allPage)
    if (this.data.page < that.data.allPage - 1) {
      that.setData({
        page: that.data.page + 1
      })
      that.getAlbum(that.data.page, 10)
    }else{
      that.setData({
        ToLoad: '',
      });
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '媛月幸福汇',
      path: '/pages/index/index?isShare=1',
      imageUrl: '/images/DefaultAvatar.png',
    }
  },
})